﻿/*
 * UBB elements
 *
 * Simple elements ( no argument )
 *
 * b, i, u, del, (right, left, center)(implement by align), code
 *
 * Advanced elements ( with zero or one argument )
 *
 * img, font, list, float, align(better use right/left/center), color
 *
 * More advanced elements ( with zero or more argument )
 *
 * table, size, cursor, quote, quotex, url
 *
 *
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Snowdreamist.Text.UBB
{
    internal class SimpleUBBElementFactory : IPrefixUBBElementFactory
    {
        public SimpleUBBElementFactory(string prefix, Func<UBBElement> func)
        {
            if (prefix == null)
                throw new ArgumentNullException("prefix");
            if (func == null)
                throw new ArgumentNullException("func");
            this.Prefix = prefix;
            this._func = func;
        }

        public string Prefix { get; private set; }

        public bool IsLabel(string content, out IUBBElementFactory factory)
        {
            if (string.Compare(this.Prefix, content, true) == 0)
            {
                factory = this;
                return true;
            }
            else
            {
                factory = null;
                return false;
            }
        }

        public UBBElement Create(UBBContent ubbContent)
        {
            return this._func();
        }

        private Func<UBBElement> _func;
    }

    /// <summary>
    /// Bold style
    /// </summary>
    public class BoldElement : UBBElement
    {
        public const string Label = "b";

        public BoldElement() : base(Label) { }

        public override object Clone()
        {
            return new BoldElement();
        }
    }

    /// <summary>
    /// Italic style
    /// </summary>
    public class ItalicElement : UBBElement
    {
        public const string Label = "i";

        public ItalicElement() : base(Label) { }

        public override object Clone()
        {
            return new ItalicElement();
        }
    }

    /// <summary>
    /// Underline style
    /// </summary>
    public class UnderlineElement : UBBElement
    {
        public const string Label = "u";

        public UnderlineElement() : base(Label) { }

        public override object Clone()
        {
            return new UnderlineElement();
        }
    }

    /// <summary>
    /// Strikethrough style, also called "delete line"
    /// </summary>
    public class StrikethroughElement : UBBElement
    {
        public const string Label = "del";

        public StrikethroughElement() : base(Label) { }

        public override object Clone()
        {
            return new StrikethroughElement();
        }
    }

    /// <summary>
    /// Code segement
    /// </summary>
    public class CodeElement : UBBElement
    {
        public const string Label = "code";

        public CodeElement() : base(Label) { }

        public override object Clone()
        {
            return new CodeElement();
        }
    }
}